package com.jsbj.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysDictData;
import com.jsbj.user.entities.SysEqu;
import com.jsbj.user.entities.SysEquFieldConfig;
import com.jsbj.user.service.ISysEquService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-equ")
//@ApiIgnore
@Api(value = "系统设备", tags = "系统设备")
public class SysEquController extends BaseController {

    @Autowired
    private ISysEquService sysEquService;

    @ApiOperation("通过1、项目编码 2、标段编码 3、用户id（权限）4、设备类型5、系统编码表查询设备列表")
    @PostMapping("/getByCondition")
    public ResultBean<List<SysEqu>> getByCondition(@RequestBody String inputParam) {
        JSONObject object = JSONObject.parseObject(inputParam);
        return new ResultBean<List<SysEqu>>(sysEquService.getByCondition(object));
    }

    @ApiOperation("通过设备编号查询设备详情")
    @PostMapping("/getInfoByEquNum")
    public ResultBean<SysEqu> getInfoByEquNum(@RequestParam String equNum) {
        return new ResultBean<SysEqu>(sysEquService.getInfoByEquNum(equNum));
    }

    @ApiOperation("根据系统查询设备类型列表")
    @GetMapping("/getEquTypeBySystemCode")
    public ResultBean<List<SysDictData>> getEquTypeBySystemCode(@RequestParam String systemCode) {
        return new ResultBean<List<SysDictData>>(sysEquService.getEquTypeBySystemCode(systemCode));
    }


    @ApiOperation(value = "添加或修改设备")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<String> add(@RequestBody List<Map<String,Object>> params) throws Exception {
        return new ResultBean<String>(sysEquService.add(params));
    }

    @ApiOperation(value = "修改设备")
    @PostMapping("/update")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<String> update(@RequestBody Map<String,Object> param) throws Exception {
        return new ResultBean<String>(sysEquService.update(param));
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean<String> delete(@RequestParam String id) throws Exception {
        return new ResultBean<String>(sysEquService.delete(id));
    }

    @ApiOperation(value = "查看详情")
    @PostMapping("/detail")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean detail(@RequestParam String id) {
        return new ResultBean<List<Map<String,Object>>>(sysEquService.detail(id));
    }

    @ApiOperation(value = "修改字段列表")
    @PostMapping("/updateDetail")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean updateDetail(@RequestParam String id) {
        return new ResultBean<Map<String,Object>>(sysEquService.updateDetail(id));
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @PostMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    public ResultBean<PageReq> getList(@RequestBody String inParam) {
        return new ResultBean<PageReq>(getPage(sysEquService.getList(inParam)));
    }


}

